package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.BedDto;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bed")
@Slf4j
@Api(tags = "床位管理相关接口")
public class BedController extends BaseController {

    @Autowired
    private BedService bedService;

    @GetMapping("/read/room/{roomId}")
    @ApiOperation(value = "根据房间ID查询床位", notes = "传入房间ID，返回该房间下的所有床位信息")
    public ResponseResult<List<BedVo>> readBedByRoomId(
            @ApiParam(value = "房间ID", required = true, example = "1001") @PathVariable("roomId") Long roomId) {
        List<BedVo> beds = bedService.getBedsByRoomId(roomId);
        return success(beds);
    }

    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据床位ID查询床位", notes = "传入床位ID，返回该床位的信息")
    public ResponseResult<BedVo> readBedById(@ApiParam(value = "床位ID", required = true, example = "1") @PathVariable Long id){
        log.info("根据ID查询床位：id={}", id);
        BedVo bedVo = bedService.getBedById(id);
        return success(bedVo);
    }

    @PostMapping("create")
    @ApiOperation(value = "新增床位", notes = "传入床位信息，创建新的床位")
    public ResponseResult createBed(@ApiParam(value = "床位信息", required = true) @RequestBody BedDto bedDto){
        log.info("新增床位：{}", bedDto);
        bedService.add(bedDto);
        return success();
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新床位信息", notes = "传入床位ID和新的床位信息，更新指定床位的信息")
    public ResponseResult updateBed(@ApiParam(value = "床位信息", required = true) @RequestBody BedDto bedDto){
        log.info("修改床位信息：{}", bedDto);
        bedService.update(bedDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除床位", notes = "传入床位ID，删除指定床位")
    public ResponseResult deleteBed(@ApiParam(value = "床位ID", required = true, example = "1") @PathVariable Long id){
        log.info("根据ID删除床位：id={}", id);
        bedService.delete(id);
        return success();
    }
}